local hongyuan = fk.CreateSkill{
    name = "os_heg__hongyuan",
}

local H = require "packages.ol_hegemony.util"

hongyuan:addEffect("active",{
  prompt = "#os_heg__hongyuan-active",
  anim_type = "support",
  can_use = function(self, player)
    return player:usedEffectTimes(hongyuan.name, Player.HistoryPhase) < 1 and not player:isKongcheng()
  end,
  card_num = 1,
  card_filter = function(self, player, to_select, selected)
    if #selected > 0 then return false end
    return Fk:currentRoom():getCardArea(to_select) == Card.PlayerHand and not Fk:getCardById(to_select):hasMark("@@alliance-public", MarkEnum.CardTempMarkSuffix)
  end,
  target_filter = Util.FalseFunc,
  on_use = function(self, room, effect)
    local card = effect.cards[1]
    room:setCardMark(Fk:getCardById(card), "@@alliance-public-inhand-turn", 1)
  end,
})

hongyuan:addEffect(fk.BeforeDrawCard,{
    anim_type = "support",
    mute = true,
    can_trigger = function(self, event, target, player, data)
        return target == player and player:hasSkill(hongyuan.name) and data.skillName == "alliance&" and table.find(player.room.alive_players, function(p) return H.compareKingdomWith(p, player) and p ~= player end)
    end,
    on_cost = function(self, event, target, player, data)
        local room = player.room
        local targets = table.filter(room.alive_players, function(p) return H.compareKingdomWith(p, player) and p ~= player end)
        target = room:askToChoosePlayers(player,{
            targets = targets,
            min_num = 1,
            max_num = 1,
            prompt = "#os_heg__hongyuan-ask:::" .. data.num,
            skill_name = hongyuan.name,
            cancelable = true,
        })
        if #target > 0 then
          event:setCostData(self,{target = target})
          player:revealBySkillName(hongyuan.name) -- FIXME
          return true
        end
      end,
    on_use = function(self, event, target, player, data)
        target = event:getCostData(self).target[1]
        local room = player.room
        room:notifySkillInvoked(player, hongyuan.name, "support")
        player:broadcastSkillInvoke(hongyuan.name)
        data.who = target
      end,
})

Fk:loadTranslationTable{
    ["os_heg__hongyuan"] = "弘援",
    [":os_heg__hongyuan"] = "①当你因“合纵”摸牌时，你可改为令与你势力相同的一名其他角色摸牌。②出牌阶段限一次，你可令一张无“合纵”标记的手牌于本回合视为有“合纵”标记。",
    ["#os_heg__hongyuan-ask"] = "弘援：你将摸%arg张牌，可改为令与你势力相同的一名其他角色摸牌",
    ["#os_heg__hongyuan-active"] = "弘援：选择一张无“合纵”标记的手牌于本回合视为有“合纵”标记",

    ["$os_heg__hongyuan1"] = "诸将莫慌，粮草已到。",
    ["$os_heg__hongyuan2"] = "自舍其身，施于天下。",
}

return hongyuan